package com.qianbao.controller.v1.money;


import com.qianbao.components.excepion.CommonException;
import com.qianbao.components.svresut.Result;
import com.qianbao.components.svversion.ApiVersion;
import com.qianbao.service.money.ReadTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collections;
import java.util.HashMap;

@Controller
@ApiVersion(1)
@RequestMapping("/moneycenter/readtime/{version}/")
public class ReadTimeController {


    @Autowired
    private ReadTimeService service;

    @ResponseBody
    @RequestMapping("/update-read-time")
    public Result updateReadTime(String readtime,String customId){

        try {
            service.saveUserReadTime(customId,readtime);
            return Result.success(Collections.emptyMap());
        } catch (CommonException e) {
            e.printStackTrace();
            return Result.fail(e.getCode(),e.getMessage());
        }
    }


    @ResponseBody
    @RequestMapping("/find-read-time")
    public Result findReadTime(String customId){
        try {
            int time = service.findUserReadTime(customId);
            HashMap<String, String> map = new HashMap<>();
            map.put("readtime",String.valueOf(time));
            return Result.success(map);
        } catch (CommonException e) {
            e.printStackTrace();
            return Result.fail(e.getCode(),e.getMessage());
        }
    }


}
